﻿@model IEnumerable<SYS_ROLE>  
@using SailHero.Soft.FrameWork.Models;
@{
    ViewBag.Title = "角色管理";
    Layout = "../Shared/_Layout.cshtml";
}
<script type="text/javascript">
    $(function () {
        $("#chkAll").click(function () {
            var flag = $(this).attr("checked");
            if (flag == "checked") {
                $("[name=CheckBoxSelect]:checkbox").each(function () {
                    $(this).attr("checked", flag);
                });
            }
            else {
                $("[name=CheckBoxSelect]:checkbox").each(function () {
                    $(this).attr("checked", false);
                });

            }
        });

        $("[name=CheckBoxSelect]").click(function () {
            $("#chkAll").attr("checked", false);
        });

        $("#edit").click(function () {
            var obj = $("[name=CheckBoxSelect]:checked");
            if (obj.length == 0) {
                $.messager.alert("提示信息", "请选择编辑项！", "info");
            }
            else if (obj.size() > 1) {
                $.messager.alert("提示信息", "一次只能编辑一项！", "info");
            }
            else {
                obj.each(function () {
                    var value = $(this).val();
                    location.href = "/Role/Edit/?id=" + value;
                });
            }
        });

        $("#delete").click(function () {

            var obj = $("[name=CheckBoxSelect]:checked");
            if (obj.length == 0) {
                $.messager.alert("提示信息", "请选择删除项！", "info");
            }
            else {
                var select = "";
                obj.each(function () {
                    select += ";" + $(this).val();
                });
                $.messager.confirm("提示信息", "确定要删除选中的【" + obj.length + "】项：", function (r) {
                    if (r) {
                        //$.messager.alert("提示信息", "删除成功！", "");
                        var url = "/Role/Delete/?id=" + select;
                        $.post(url,
                function (data) {
                    if (data == "success") {
                        window.location.href = "/Role/Index";
                    }
                    else {
                        $.messager.alert("错误信息", "删除失败", "error");
                    }
                });
                    }
                });
            }
        });

        $("#authorization").click(function () {
            var obj = $("[name=CheckBoxSelect]:checked");
            if (obj.length == 0) {
                $.messager.alert("提示信息", "请选择一项！", "info");
            }
            else if (obj.size() > 1) {
                $.messager.alert("提示信息", "一次只能选择一项！", "info");
            }
            else {
                obj.each(function () {
                    var value = $(this).val();
                    location.href = "/Role/AuthorizationSet/?id=" + value;
                });
            }
        });

        $("#userSet").click(function () {
            var obj = $("[name=CheckBoxSelect]:checked");
            if (obj.length == 0) {
                $.messager.alert("提示信息", "请选择一项！", "info");
            }
            else if (obj.size() > 1) {
                $.messager.alert("提示信息", "一次只能选择一项！", "info");
            }
            else {
                obj.each(function () {
                    var value = $(this).val();
                    location.href = "/Role/UserSet/?id=" + value;
                });
            }
        });
    });
</script>

<table border="0" cellpadding="0" cellspacing="0" style="width: 100%;">
    <tr>
        <td>
            <table style="width: 100%; margin-top: 5px;" cellpadding="0" cellspacing="0">
                <caption class="tcaption">
                    <table style="width: 100%;" cellpadding="0" cellspacing="0" border="0">
                        <tr>
                            <td align="left">
                                <table class="tableTitle">
                                    <tr>
                                        <td width="80px">
                                            <span style="color: Green; font-weight: bold; padding-left: 5px;">部门列表</span>
                                        </td>
                                        <td width="50px">
                                            <a href="/Role/Create" class="operateA">
                                                <img style="vertical-align: middle; border: 0;" src="@Href("../../Content/images/add.png")" alt="新增" />&nbsp;新增</a>
                                        </td>
                                        <td width="50px">
                                            <a id="edit">
                                                <img style="vertical-align: middle" src="@Href("../../Content/images/edit2.png")" alt="修改" />&nbsp;编辑</a>
                                        </td>
                                        <td width="50px">
                                            <a id="delete">
                                                <img style="vertical-align: middle" src="@Href("../../Content/images/delete.png")" alt="删除" />&nbsp;删除</a>
                                        </td>
                                        <td width="70px">
                                            <a id="authorization">
                                                <img style="vertical-align: middle" src="@Href("../../Content/images/edit2.png")" alt="权限设置" />&nbsp;权限设置</a>
                                        </td>
                                        <td width="70px">
                                            <a id="userSet">
                                                <img style="vertical-align: middle" src="@Href("../../Content/images/edit2.png")" alt="成员设置" />&nbsp;成员设置</a>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </table>
                </caption>
                <tr>
                    <td>
                        <table class="mytable" cellspacing="0" border="1" style="width: 100%; border-collapse: collapse;">
                            <tr>
                                <th>
                                    NO.
                                </th>
                                <th>
                                    <input id="chkAll" type="checkbox" />
                                </th>
                                <th>
                                    角色名称
                                </th>
                                <th>
                                    角色描述
                                </th>
                            </tr>
                            @{
                                int num = 0;
                                foreach (var mod in Model)
                                {
                                    num++;
                                <tr>
                                    <td align="center" style="width: 30px;">
                                        @num
                                    </td>
                                    <td align="center" style="width: 30px;">
                                        <input id="CheckBoxSelect" name="CheckBoxSelect" value="@mod.ROLEID" type="checkbox" />
                                    </td>
                                    <td align="center" style="width: 10%;">
                                        @mod.ROLENAME
                                    </td>
                                    <td align="center">
                                        @mod.REMARK
                                    </td>
                                </tr>
                                }
                            }
                        </table>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>
